<template>
  <div class="productProcess">

        
    <div class="table_th">
      <div class="tr tr-left">上链中小微企业</div>
      <div class="tr tr-right">地区</div>
    </div>

    <div class="table_main_body">
      <div class="table_inner_body" :style="{top: tableTop + 'px'}">
          <div class="table_tr" v-for="(item,index) in tableList" :key="index">
            <div class="tr-left">{{item.name}}</div>
            <div class="tr-right">{{item.address}}</div>
          </div>
      </div>
  </div>
      

  </div>
</template>

<script setup name="list">

import { getCurrentInstance, onBeforeUnmount, onMounted, proxyRefs, ref } from "vue"
import { useRouter } from "vue-router"
const {proxy} = getCurrentInstance()
const router = useRouter()

const showFlag = ref(true)
const tableTimer = ref(null)
const tableTop = ref(0)
const tableList = ref([{
          "name":'河南韦特机械设备',
          "address":"郑州"
        },
        {
          "name":'河南韦特机械设备1',
          "address":"郑州"
        },{
          "name":'河南韦特机械设备2',
          "address":"郑州"
        },
        {
          "name":'河南韦特机械设备3',
          "address":"郑州"
        },{
          "name":'河南韦特机械设备4',
          "address":"郑州"
        },
        {
          "name":'河南韦特机械设备5',
          "address":"郑州"
        },{
          "name":'河南韦特机械设备6',
          "address":"郑州"
        },
        {
          "name":'河南韦特机械设备7',
          "address":"郑州"
        },{
          "name":'河南韦特机械设备8',
          "address":"郑州"
        },
        {
          "name":'河南韦特机械设备9',
          "address":"郑州"
        }])

const tableListSize = ref(0)
const componentTimer = ref(null)
const title = ref('标题')
const visibleSize = ref(6)////容器内可视最大完整行数
const lineHeight = ref(49)////每行的实际高度（包含margin-top/bottom,border等）
const componentTimerInterval = ref(3600000)////刷新数据的时间间隔
const tableTimerInterval = ref(100)////向上滚动 1px 所需要的时间，越小越快，推荐值 100


const props = defineProps({
    activeFactoryId:{
        type:String,
        default:''
    }
})

// watch: {
//     activeFactoryId(val, oldVal) {
//       clearInterval(this.componentTimer);
//       this.bsGetProductProcess();
//       this.componentTimerFun();
//     }
//   }



function tableActionFun(){
    tableListSize.value = tableList.value.length;
      if (tableListSize.value > visibleSize.value) {
        tableList.value = tableList.value.concat(tableList.value);
        tableTimerFun();
      } else {
        fillTableList();
      }
}

 //当数据过少时，不触发自动轮播事件，并填充没有数据的行，参数根据实际情况修改即可
function fillTableList(){
    var addLength = visibleSize.value - tableListSize.value

    for (var i = 0; i < addLength; i++) {
        tableList.value.push({
          planNo: "-",
          type: "-",
          startDate: "-",
          endDate: "-",
          process: "-"
        });
      }
}

function tableTimerFun(){

    var count = 0;
      tableTimer.value = setInterval(() => {
        if (count < (tableList.value.length / 2) * lineHeight.value) {
          tableTop.value -= 1;
          count++;
        } else {
          count = 0;
          tableTop.value = 0;
        }
      }, tableTimerInterval.value)
}

function componentTimerFun(){
    componentTimer.value = setInterval(() => {
         bsGetProductProcess();
      }, componentTimerInterval.value);
}


onMounted(() =>{
    // 加载数据 函数 xx
    tableActionFun()
    componentTimerFun() // 开启定时器
})

onBeforeUnmount(() =>{
    //组件卸载之前执行的函数
    clearInterval(componentTimer.value);
    clearInterval(tableTimer.value);

})


</script>

<style lang="scss" scoped>

.productProcess {
  background: url('@/assets/business/top_left.png') no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 100%;

  display: flex;
  flex-direction: column;
}

.table_th {
  margin-top: 10px;
  margin-left: 10px;
  margin-right: 10px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  background-color: rgba($color: #0054FF, $alpha: 0.5);
  
}

.tr {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-sizing: border-box;
  padding: 0 5px;
  text-align: center;
  font-size: 13px;
  color: #fff;
}
.tr-left{
  margin-left: 10px;
}
.tr-right{
  margin-right: 10px;
}

 
 
.th_style {
  color: rgb(0, 221, 253);
  font-weight: bold;
  font-size: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-sizing: border-box;
  padding: 0 5px;
  text-align: center;
}
.table_main_body {
  flex: 1;
  overflow: hidden;
  position: relative;
  margin-left: 10px;
  margin-right: 10px;
  margin-bottom: 10px;
}
.table_inner_body {
  width: 100%;
  position: absolute;
  left: 0;
}
.table_tr {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  // line-height: 20px;
  color: #eee;
  font-size: 13px;
  background: rgba(3, 145, 167, 0.1);
  border: 1px solid rgb(4, 114, 131);
  margin-top: 7px;
}


</style>
